///////////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2009. Dimarik
//
///////////////////////////////////////////////////////////////////////////////

package
{

import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.net.URLRequest;
import flash.utils.getClassName;
import flash.utils.getQualifiedClassName;
import flash.utils.getQualifiedSuperclassName;

import ru.goodcore.utils.ActivityListener;

/**
 *  @author				Dimarik
 *  @version			1.0
 *  @langversion		3.0
 *  @playerversion		9.0
 * 
 */
[SWF(width="800", height="600", frameRate="21", backgroundColor="#E0EEEE")]

public class LoadFramedApplicationTest extends Sprite {

	//-------------------------------------------------------------------------
	//
	//   Constructor
	//
	//-------------------------------------------------------------------------

	public function LoadFramedApplicationTest() {
		super();
		super.addEventListener(Event.ADDED_TO_STAGE, this.initialize);
	}

	//-------------------------------------------------------------------------
	//
	//   Private variables
	//
	//-------------------------------------------------------------------------

	/**
	 * @private 
	 */
	private var _activity:		ActivityListener;

	//-------------------------------------------------------------------------
	//
	//   Private methods
	//
	//-------------------------------------------------------------------------

	public function initialize(event:Event):void {
		(event.target as IEventDispatcher).removeEventListener(event.type, arguments.callee);

		super.stage.scaleMode = StageScaleMode.NO_SCALE;
		super.stage.align = StageAlign.TOP_LEFT;

		trace(getClassName(this), 'initialize');

		//this._activity = new ActivityListener();
		//super.stage.addChild(this._activity);

		var loader:Loader = new Loader();
		super.addChild(loader);
		//loader.load( new URLRequest('FramedApplicationTest.swf') );
		loader.load( new URLRequest('http://fillmult.ru/fill_lepra/shark.gif') );
		loader.x = 200;
		loader.opaqueBackground = 0xFF0000;
		loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.handler_complete);
	}

	//-------------------------------------------------------------------------
	//
	//   Events handlers
	//
	//-------------------------------------------------------------------------

	private function handler_complete(event:Event):void {
		trace(this, 'handler_complete');
		var li:LoaderInfo = event.target as LoaderInfo;
		var loader:Loader = li.loader;
		
		//super.addChild(loader);
		li.removeEventListener(Event.COMPLETE, this.handler_complete);
		//loader.load( new URLRequest('http://fillmult.ru/fill_lepra/shark.gif') );
		
		var aaa:DisplayObject = loader.content as DisplayObject;
		trace(getQualifiedClassName(aaa));
		trace(getQualifiedSuperclassName(aaa));
		var loader2:Loader = aaa.loaderInfo.loader;
		trace(loader == loader2); //
	}

}
}